async function setInfo(data) {
  const userInfo = data.data
  console.log(userInfo);
  localStorage.setItem('uname', userInfo.username)
  localStorage.setItem('token', userInfo.token)
  pxmu.success(data.message)
  setTimeout(function () {
    location.href = 'index.html'
  }, 1500)
}

async function loginInfo(username, password) {
  const res = await axios({
    url: '/login',
    method: 'POST',
    data: {
      username,
      password
    }
  })
  setInfo(res)
  // console.log(res);
}

document.querySelector('#btn-login').addEventListener('click', e => {
  e.preventDefault()
  const form = document.querySelector('.login-form')
  const data = serialize(form, { hush: true, empty: true })
  const isRight = regUserInfo(data.username, data.password)

  if (isRight) {
    const username = data.username//usn:shenqq160 pwd:12345678
    const password = data.password
    loginInfo(username, password)
  }
})

